﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentData;
using System.Dynamic;

namespace Eleanor.DAL
{
    public class SubjectDAL : DALBase
    {
        public List<dynamic> SelectAll()
        {
            var command = DefaultContext
                        .Sql("SubjectSelectALL")
                        .CommandType(DbCommandTypes.StoredProcedure);
            return command.QueryMany<dynamic>();
        }

        public dynamic CustomMapperUsingDynamic(dynamic row)
        {
            if (row == null)
            {
                return null;
            }
            dynamic subject = new ExpandoObject();
            subject.SubjectId = row.subject_id;
            subject.Value = row.value;
            subject.CountOfPaint = row.count_of_paint;
            subject.CreateDate = row.create_date;
            subject.UpdateDate = row.update_date;
            return subject;
        }
        
        public dynamic Select(string subjectName)
        {
            const string sql = @"select * from subject where value=@0";
            return CustomMapperUsingDynamic(DefaultContext.Sql(sql).Parameters(subjectName).QuerySingle<dynamic>());
        }
    }
}
